<script setup lang="ts">
// 生成key
import {getRandomKeyPair} from "@/common/lib/keyring";
import bip39 from "bip39";

// 生成一个12个单词的助记词
const mnemonic = bip39.generateMnemonic();

const publicKey = ref('');
const privateKey = ref('');
const SeedPhrase = ref('');


// 生成公钥 私钥 助记词
const handleGenerateKey = async () => {
  let keypair = await getRandomKeyPair();
  if (keypair) {
    publicKey.value = 'MOS' + keypair.publicKey.toString().substring(4);
    privateKey.value = keypair.privateKey;
    SeedPhrase.value = mnemonic;
  }
};

handleGenerateKey();

</script>

<template>
  <div class="full-router">
    <div class="full-inner">
      <page-header :title="$t('public.viewTheKey')"></page-header>

      <div class="cover-content _effect pr-[15px]">
        <div class="import-key-container">

          <div class="import-key-tip">{{ $t('public.privateKeyTip') }}:</div>
          <n-input
              :autosize="{ minRows: 5, maxRows: 5 }"
              placeholder=""
              class="import-key-input"
              type="textarea"
              readonly
              v-model:value="privateKey"
          ></n-input>

          <div class="import-key-tip">{{ $t('public.publicKeyTip') }}:</div>
          <n-input
              :autosize="{ minRows: 5, maxRows: 5 }"
              placeholder=""
              class="import-key-input"
              type="textarea"
              readonly
              v-model:value="publicKey"
          ></n-input>

          <div class="import-key-tip">{{ $t('public.viewTheSeedPhraseTip') }}:</div>
          <n-input
              :autosize="{ minRows: 5, maxRows: 5 }"
              placeholder=""
              class="import-key-input"
              type="textarea"
              readonly
              v-model:value="SeedPhrase"
          ></n-input>

          <span class="check-tip text-center cursor-pointer ml-[4px]" >
              {{ $t('public.memorizeCues') }}
          </span>

          <n-button @click="$router.push({ name: 'index' })" class="import-key-btn">
            {{ $t('public.createAWallet') }}
          </n-button>
        </div>
      </div>

    </div>
  </div>
</template>

<style lang="scss" scoped>
.icon-img {
  width: 24px;
  height: 24px;
}
.import-key-container {
  padding-left: 15px;

  .import-key-tip {
    font-size: 12px;
    color: #222;
    margin-top: 20px;
  }
  .import-key-input {
    margin-top: 10px;
    font-size: 14px;
    color: #999999;
    width: 345px;
    height: 58px !important;
  }
  .import-key-protocol {
    margin-top: 8px;
    font-size: 14px;
    color: #999999;
    margin-right: 0;
  }
  .import-key-btn {
    background: $color-primary;
    box-shadow: 0px 2px 6px 0px rgba(210, 0, 244, 0.09);
    border-radius: 50px;
    width: 178px;
    height: 44px;
    margin: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-family: PingFangSC-Medium, PingFang SC;
    font-weight: 500;
    color: #ffffff;
    line-height: 20px;
    text-shadow: 0px 2px 6px rgba(210, 0, 244, 0.09);
    margin-top: 58px;
    &:active {
      border-color: $color-primary;
    }
  }
  .check-tip {
    margin-top: 10px;
    color: #999999;
    font-size: 12px;
  }
  .protocol-tip {
    color: $color-primary;
    cursor: pointer;
  }
  :deep(.n-input-wrapper){
    z-index: 20;
  }
  :deep(.n-input__border){
    background-color: #ecf5ff;
  }
}
</style>
